<?php
class MyobjectsController extends Zend_Controller_Action{
	
	protected $token;
	
	public  function preDispatch(){
		//$session = new Zend_Session_Namespace('vivier');
		$token = new Zend_Session_Namespace('token');
		$token->delete = md5(time()*rand(1,10));
		$this->token = $token;
		
	}
	
	public function indexAction() {
		$auth = Zend_Auth::getInstance ();
		if ($auth->hasIdentity ()) {
			$userMapper = new Application_Model_UserMapper();
			$userConnected = $userMapper->find($auth->getIdentity ()->id_user);
			$offerMapper = new Application_Model_OfferMapper();
			$where = array('id_user = ?' => $userConnected->getUserId() );
			$offers = $offerMapper->fetchAll($where);
			
			$this->view->offers = $offers; 
			
			$this->view->token = $this->token;
			if(0 == count($offers))
				$this->view->message = 'You don\'t have any object, please add new objects';
			
			
		}else{
		
			$this->_helper->redirector ('index', 'index');
		}
	}
	
}